# 对于POST、PUT等方法，可以使用Pydantic模型接收请求体
# axios.post('',{'name':'sdf':'age':''})
from fastapi import FastAPI
import uvicorn
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: float

app = FastAPI()
@app.post('/items/')
async def create_item(item: Item):  # 自动解析请求体为Item对象
    return {"item_name": item.name, "item_price": item.price}
if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=8000)

# 访问：http://127.0.0.1:8000/items/
# 请求体：{"name": "apple", "price": 1.5}
